package frontend.view;

import java.awt.Color;
import java.awt.Dimension;

import javax.swing.DefaultCellEditor;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ScrollPaneConstants;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;

public class TablePanel extends JPanel {

	private static final long serialVersionUID = 1L;
	private JTable table;
	private JScrollPane scroll;

	public TablePanel() {
		setBackground(Color.WHITE);
		DefaultTableModel dm = new DefaultTableModel();
		String[] columnNames = new String[] { "Id", "Last name", "First name",
				"Mobile number", "Email", "Function", "Username", "Role" };

		Object[][] data = { {} };

		dm = new DefaultTableModel(data, columnNames);

		table = new JTable(dm);
		table.getColumnModel().getColumn(0).setPreferredWidth(15);
		TableColumn roleColumn = table.getColumnModel().getColumn(7);
		String[] roleString = { "Director General", "Director de Departament",
				"Director de HR", "Recruiter", "Administratorul aplicatiei",
				"Viewer" };
		WideComboBox role = new WideComboBox(roleString);
		roleColumn.setCellEditor(new DefaultCellEditor(role));

		scroll = new JScrollPane(table);
		scroll.setPreferredSize(new Dimension(800, 400));
		scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
		this.add(scroll);
	}

	public void updateTable(DefaultTableModel dm) {
		this.table.setModel(dm);
	}

	public JTable getTable() {
		return table;
	}

	public void setTable(JTable table) {
		this.table = table;
	}

}
